<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

include_once("$g4[path]/head.sub.php");
include_once("$g4[path]/lib/outlogin.lib.php");
include_once("$g4[path]/lib/visit.lib.php");
include_once("$g4[path]/lib/connect.lib.php");
include_once("$g4[path]/lib/popular.lib.php");
include_once("$g4[path]/lib/category.lib.php");

if ($is_dhtml_editor) {
    include_once("$g4[path]/lib/cheditor4.lib.php");
    echo "<script src='$g4[cheditor4_path]/cheditor.js'></script>";
    echo cheditor1('wr_content', '100%', '250');
}
?>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:270px;
	z-index:1;
}
-->
</style>
<script type="text/javascript">
// 글자수 제한
var char_min = parseInt(<?=$write_min?>); // 최소
var char_max = parseInt(<?=$write_max?>); // 최대


$(document).ready(function(){
	if ($("#wr_area_select").val()=="4"){
		$("#searchBtn").show();
	}
});

function addComma(obj,fLen)
{ 
	if(event.keyCode == 37 || event.keyCode == 39 ) 
	{ 
		return;
	}
	var fLen = fLen || 2; 

	var strValue = obj.value.replace(/,|\s+/g,'');
	var strBeforeValue = (strValue.indexOf('.') != -1)? strValue.substring(0,strValue.indexOf('.')) :strValue ;
	var strAfterValue = (strValue.indexOf('.') != -1)? strValue.substr(strValue.indexOf('.'),fLen+1) : '' ;

	if(isNaN(strValue))
	{
		alert(strValue.concat(' -> 숫자가 아닙니다.'));
		obj.value = "가격 (숫자로만입력)";
		return false;
	}

	var intLast = strBeforeValue.length-1;

	var arrValue = new Array;
	var strComma = '';

	for(var i=intLast,j=0; i >= 0; i--,j++)
	{ 
		if( j !=0 && j%3 == 0) 
		{ 
			strComma = ',';
		}
		else
		{
			strComma = '';
		}
		arrValue[arrValue.length] = strBeforeValue.charAt(i) + strComma ;
	}
	obj.value= arrValue.reverse().join('') + strAfterValue; 
}


//스트립트 추가
function goFocus(obj){
	switch(obj.name){
	case "itemBrand":
		if (obj.value == "브랜드 (10글자이내)")
			obj.value='';
		break;
	case "itemName":
		if (obj.value == "제품명 (10글자이내)")
			obj.value='';
		break;
	case "itemPrice":
		if (obj.value == "가격 (숫자로만입력)")
			obj.value='';
		break;
	case "wr_content":
		if (obj.value == "제품설명 (140글자이내)")
			obj.value='';
		break;
	}
}
function goBlur(obj){
	if (obj.value==""){
		switch(obj.name){
		case "itemBrand":
			obj.value='브랜드 (10글자이내)';
			break;
		case "itemName":
			obj.value='제품명 (10글자이내)';
			break;
		case "itemPrice":
			obj.value='가격 (숫자로만입력)';
			break;
		case "wr_content":
			obj.value= "제품설명 (140글자이내)";
			break;
		}
	}
}

function checkLength(f, n){
	var limit = n;
	var StrLen = f.value;
	var cnt = 0;
	var limitLen = 0; 
	
	for (i=0; i<StrLen.length; i++) {
        ch = StrLen.charAt(i);
        if (escape(ch).length > 4) {
            cnt += 1;
        } else {
            cnt += 0.5;
        }

        if(cnt > limit){
    		alert("한글("+limit+") 영문("+(limit*2)+") 글자 까지만 입력 가능합니다.");
    		f.value = f.value.substring(0, limitLen);
    		f.focus();
    		return;
    	}
        limitLen++;
    }
}
</script>

<form name="fwrite" method="post" onsubmit="return fwrite_submit(this);" enctype="multipart/form-data" style="margin:0px;" action="./write_sellitem_update.php">
<input type=hidden name=null> 
<input type=hidden name=w        value="<?=$w?>">
<input type=hidden name=bo_table value="<?=$bo_table?>">
<input type=hidden name=wr_id    value="<?=$wr_id?>">
<input type=hidden name=sca      value="<?=$sca?>">
<input type=hidden name=sfl      value="<?=$sfl?>">
<input type=hidden name=stx      value="<?=$stx?>">
<input type=hidden name=spt      value="<?=$spt?>">
<input type=hidden name=sst      value="<?=$sst?>">
<input type=hidden name=sod      value="<?=$sod?>">
<input type=hidden name=page     value="<?=$page?>">

<input type="hidden" name="wr_subject" value="제목없음" />

<table width="1007" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="706" valign="top" class="right_line">
      <table width="706" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="50">&nbsp;</td>
      </tr>
      
      <tr>
        <td height="80" align="center" valign="top"><a href="/bbs/board_sellitem.php?bo_table=sellitem"><img src="../img/comm/logo.gif" width="302" height="71" border="0" /></a></td>
      </tr>
      <tr>
        <td height="85" valign="top">

          <table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="left"><img src="../img/product/bt_catalog.gif" width="99" height="24" /></td>
            <td align="right"><a href="#"><img src="../img/comm/bt_write.gif" width="102" height="32" border="0" /></a></td>
          </tr>
          <tr>
            <td colspan="2">
            	<input type="hidden" name="sfl" value="wr_subject||wr_content"/>
        		<input type="hidden" name="sop" value="and"/>
	            <input name="stx" type="text" class="box5" id="stx"  style="vertical-align:top;"  /><input type="image" src="../img/product/bt_search.gif"  style="vertical-align:top;" />
            </td>
          </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td height="1" bgcolor="D1D1D1"></td>
      </tr>
      <tr>
        <td height="104" align="left" valign="top">


			<div style="overflow:hidden; padding-top:10px; margin-bottom:10px;">
				<div style="float:left;">
				<input type="radio" name="chkItem" value="sell" <?if($chkItem!="buy"){echo "checked";}?> <?if($w!="")echo "disabled";?> /> <b>판매</b>&nbsp;&nbsp;&nbsp;&nbsp; 
				<input type="radio" name="chkItem" value="buy" <?if($chkItem=="buy"){echo "checked";}?> <?if($w!="")echo "disabled";?> /> <b>구매</b>
				</div>&nbsp;&nbsp;
				<input type="text" name="wr_area" id="wr_area" value="<?=$write['wr_area']?>" border="0" width="200" readonly="readonly" style="border:1px solid #ccc; width:300px; height:18px; line-height:18px; vertical-align:middle;">
				<span id="searchBtn" style="display:none;"><a href="javascript:;" onclick="win_zip('fwrite', 'mb_zip1', 'mb_zip2', 'wr_area', 'mb_addr2');"><img src="../img/btn_search.gif" alt=""  hspace="3" border="0" style="vertical-align:middle;"/></a></span>
				<div style="float:right; border:2px solid #d6d6d6;width:158px; overflow:hidden;margin-right:30px;">
					<select name=wr_area_select id="wr_area_select" required itemname="지역" onchange="javascript:changeArea(this.value)">
    					<option value="">지역&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<? if($member[mb_addr1_1]){ ?><option value="1" <? if($member[mb_addr1_1]==$write['wr_area']) echo "selected";?>>직거래가능지역1</option><? } ?>
<? if($member[mb_addr2_1]){ ?><option value="2" <? if($member[mb_addr2_1]==$write['wr_area']) echo "selected";?>>직거래가능지역2</option><? } ?>
<? if($member[mb_addr3_1]){ ?><option value="3" <? if($member[mb_addr3_1]==$write['wr_area']) echo "selected";?>>직거래가능지역3</option><? } ?>
    					<option value="4" <? if($write['wr_area'] && $write['wr_area']!=$member[mb_addr1_1] && $write['wr_area']!=$member[mb_addr2_1] && $write['wr_area']!=$member[mb_addr3_1] ) echo "selected";?>>직접입력</option>
    				</select>
				</div>
				<!-- <div style="float:right;"><img src="../img/product/txt_local.gif" align="absmiddle" /><span style="display:inline-block;border:1px solid #e2e2e2; height:19px; width:115px; text-align:right;margin-right:30px; margin-left:10px;" ><img src="../img/product/select_img1.gif" align="absmiddle" /></span>
				</div> -->
			</div>

			<div style="overflow:hidden;margin-bottom:24px;">

				<div style="float:left; border:2px solid #d6d6d6;width:158px; overflow:hidden;margin-right:10px;">
					<select name=ca_name id="ca_name" required itemname="분류" style="border:none;">
    					<option value="">카테고리<?=$category_option?>
    				</select>
				</div>
				<div style="float:left; border:2px solid #d6d6d6;width:157px; height:26px; font-weight:bold;margin-right:10px;">
					<span style="display:inline-block; padding:5px 0 0 10px;"><input type="text" id="itemBrand" name="itemBrand" onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" onkeyup="javascript:checkLength(this, 10);" value="<?if($write['itemBrand']!="")echo $write['itemBrand'];else echo "브랜드 (10글자이내)";?>" style="border:none;"/></span>
				</div>
				<div style="float:left; border:2px solid #d6d6d6;width:157px; height:26px; font-weight:bold;margin-right:10px;">
					<span style="display:inline-block; padding:5px 0 0 10px;"><input type="text" id="itemName" name="itemName" onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" onkeyup="javascript:checkLength(this, 10);"  value="<?if($write['itemName']!="")echo $write['itemName'];else echo "제품명 (10글자이내)";?>" style="border:none;"/></span>
				</div>
				<div style="float:left; border:2px solid #d6d6d6;width:157px; height:26px; font-weight:bold;">
					<span style="display:inline-block; padding:5px 0 0 10px;"><input type="text" id="itemPrice" name="itemPrice" onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" value="<?if($write['itemPrice']!="" && $write['itemPrice']!="0" )echo number_format($write['itemPrice']);else echo "가격 (숫자로만입력)";?>" style="border:none;" onkeyup="addComma(this)" /></span>
				</div>
			</div>

			<div style="overflow:hidden; width:706px; margin-bottom:10px;">
				<div style="float:left;width:170px;padding-top:10px;">
					<input type="checkbox" id="dealDirect" name="dealDirect" value='1' <?if($write['wr_1']=="1")echo "checked";?> /> 직거래<br/>
					<input type="checkbox" id="dealService" name="dealService" value='1' <?if($write['wr_2']=="1")echo "checked";?> /> 택배
				</div>
				<div style="float:left; width:505px;">
					<table width=100% cellpadding=0 cellspacing=0>
				        <tr>
				            <td width=50% align=left valign=bottom>
				                <!-- <span style="cursor: pointer;" onclick="textarea_decrease('wr_content', 10);"><img src="<?=$board_skin_path?>/img/up.gif"></span>
				                <span style="cursor: pointer;" onclick="textarea_original('wr_content', 10);"><img src="<?=$board_skin_path?>/img/start.gif"></span>
				                <span style="cursor: pointer;" onclick="textarea_increase('wr_content', 10);"><img src="<?=$board_skin_path?>/img/down.gif"></span></td> -->
				            <td width=50% align=right><? if ($write_min || $write_max) { ?><span id=char_count></span>글자<?}?></td>
				        </tr>
			        </table>
			        <textarea id="wr_content" cols="100" name="wr_content" class=tx style='width:100%; word-break:break-all;' rows=10 itemname="내용" required onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);"
			        <? if ($write_min || $write_max) { ?>onkeyup="check_byte2('wr_content', 'char_count');checkLength(this, 140);"<?}?>><?if($param_data) echo "#".$param_data."\n";?><?=$content==""?"제품설명 (140글자이내)":$content?></textarea>
			        <? if ($write_min || $write_max) { ?><script type="text/javascript"> check_byte2('wr_content', 'char_count');checkLength(document.fwrite.wr_content, 140); </script><?}?>
				</div>
			</div>
			
			<div style="overflow:hidden; margin-bottom:30px;">
				<div style="float:left;padding-right:20px;padding-top:5px;">
					<img src="../img/product/bt_file.gif" align="absmiddle" />
					<span onclick="add_file();" style="cursor:pointer;"><img src="<?=$board_skin_path?>/img/btn_file_add.gif"></span> 
                	<span onclick="del_file();" style="cursor:pointer;"><img src="<?=$board_skin_path?>/img/btn_file_minus.gif"></span>
                	<table id="variableFiles" cellpadding=0 cellspacing=0></table>
        <script type="text/javascript">
        var flen = 0;
        function add_file(delete_code)
        {
            var upload_count = <?=(int)$board[bo_upload_count]?>;
            if (upload_count && flen >= upload_count)
            {
                alert("상품 이미지는 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
                return;
            }

            var objTbl;
            var objRow;
            var objCell;
            if (document.getElementById)
                objTbl = document.getElementById("variableFiles");
            else
                objTbl = document.all["variableFiles"];

            objRow = objTbl.insertRow(objTbl.rows.length);
            objCell = objRow.insertCell(0);

            objCell.innerHTML = "<input type='file' class='ed' name='bf_file[]' title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능'>";
            if (delete_code)
                objCell.innerHTML += delete_code;
            else
            {
                <? if ($is_file_content) { ?>
                objCell.innerHTML += "<br><input type='text' class='ed' size=50 name='bf_content[]' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
                <? } ?>
                ;
            }

            flen++;
        }

        <?=$file_script; //수정시에 필요한 스크립트?>

        function del_file()
        {
            // file_length 이하로는 필드가 삭제되지 않아야 합니다.
            var file_length = <?=(int)$file_length?>;
            var objTbl = document.getElementById("variableFiles");
            if (objTbl.rows.length - 1 > file_length)
            {
                objTbl.deleteRow(objTbl.rows.length - 1);
                flen--;
            }
        }
        </script>
				</div>
				<div style="float:left;">
					<div>연락처 : <input type="hidden" id="phoneNum" name="phoneNum" value="<?=$member['mb_tel']?>"/><?=$member['mb_tel']?>
					<input type="checkbox" id="colseAddr" name="colseAddr" value='1' <?if($write['wr_5']=="1")echo "checked";?> /> 비공개
					</div>
					<div>이메일 : <input type="hidden" id="email" name="email" value="<?=$member['mb_email']?>"/><?=$member['mb_email']?>
					</div>
				</div>
				<div style="float:right;padding-right:30px;padding-top:5px;">
					<input type="image" id="btn_submit" src="../img/product/bt_upload.gif" align="absmiddle" border=0 accesskey='s' />
				</div>
			</div>



		</td>
      </tr>

      <tr>
        <td height="100">&nbsp;</td>
      </tr>
    </table></td>
    <td width="300" valign="top"><table width="270" border="0" align="right" cellpadding="0" cellspacing="0">
      <tr>
        <td height="17">&nbsp;</td>
      </tr>
      <tr>
        <td align="right">
	        <a href="/"><img src="../img/comm/smenu_home.gif" alt="" width="10" height="11" border="0" /></a>
	        <img src="../img/comm/smenu_line.gif" width="2" height="12" hspace="7" />
	        <a href="<?=$g4['path']?>/bbs/board_sellitem.php?bo_table=sellitem"><img src="../img/comm/smenu_buy.gif" width="38" height="11" border="0" /></a>
	        <img src="../img/comm/smenu_line.gif" alt="" width="2" height="12" hspace="7" />
	        <a href="<?=$g4['path']?>/bbs/board_sellhome.php?bo_table=sellhome"><img src="../img/comm/smenu_home01.gif" width="37" height="11" border="0" /></a>
	        <img src="../img/comm/smenu_line.gif" alt="" width="2" height="12" hspace="7" />
	        <a href="#"><img src="../img/comm/smenu_job.gif" width="47" height="11" border="0" /></a>
        </td>
      </tr>
      <tr>
        <td height="38">&nbsp;</td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?=outlogin("basic2"); // 외부 로그인 ?></td>
          </tr>
          
        </table></td>
      </tr>
      <tr>
        <td height="90" valign="top">
		</td>
      </tr>
      
    </table></td>
  </tr>
</table>
</form>




<script type="text/javascript" src="<?="$g4[path]/js/jquery.kcaptcha.js"?>"></script>
<script type="text/javascript">
<?
// 관리자라면 분류 선택에 '공지' 옵션을 추가함
if ($is_admin) 
{
    /*echo "
    if (typeof(document.fwrite.ca_name) != 'undefined')
    {
        document.fwrite.ca_name.options.length += 1;
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].value = '공지';
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].text = '공지';
    }";*/
} 
?>

with (document.fwrite) 
{
    if (typeof(wr_name) != "undefined")
        wr_name.focus();
    /*else if (typeof(wr_subject) != "undefined")
        wr_subject.focus();*/
    else if (typeof(wr_content) != "undefined")
        wr_content.focus();

    if (typeof(ca_name) != "undefined")
        if (w.value == "u")
            ca_name.value = "<?=$write[ca_name]?>";
}

function html_auto_br(obj) 
{
    if (obj.checked) {
        result = confirm("자동 줄바꿈을 하시겠습니까?\n\n자동 줄바꿈은 게시물 내용중 줄바뀐 곳을<br>태그로 변환하는 기능입니다.");
        if (result)
            obj.value = "html2";
        else
            obj.value = "html1";
    }
    else
        obj.value = "";
}

function fwrite_submit(f) 
{
    /*
    var s = "";
    if (s = word_filter_check(f.wr_subject.value)) {
        alert("제목에 금지단어('"+s+"')가 포함되어있습니다");
        return false;
    }

    if (s = word_filter_check(f.wr_content.value)) {
        alert("내용에 금지단어('"+s+"')가 포함되어있습니다");
        return false;
    }
    */

    if ($("#wr_area").val()==""){
        alert ("거래지역을 선택하십시오.");
        return false;
    }
    if ($("#ca_name").val()==""){
        alert ("카테고리를 선택하십시오.");
        return false;
    }
    if ($("#itemBrand").val()=="" || $("#itemBrand").val()=="브랜드 (10글자이내)"){
        alert ("브랜드를 입력하십시오.");
        return false;
    }
    if ($("#itemName").val()=="" || $("#itemName").val()=="제품명 (10글자이내)"){
        alert ("제품명을 입력하십시오.");
        return false;
    }
    if ($("#itemPrice").val()=="" || $("#itemPrice").val()=="가격 (숫자로만입력)"){
        alert ("가격을 입력하십시오.");
        return false;
    }
    if ($("#phoneNum").val()==""){
        alert ("연락처를 입력하십시오.");
        return false;
    }
    if ($("#email").val()==""){
        alert ("이메일을 입력하십시오.");
        return false;
    }

    if (!$("#dealDirect").attr("checked")
       	&& !$("#dealService").attr("checked")){
       	alert ("직거래와 택배 중 둘 중에 하나는 필수로 선택해야 합니다.");
       	return false;
    }

    if (document.getElementById('char_count')) {
        if (char_min > 0 || char_max > 0) {
            var cnt = parseInt(document.getElementById('char_count').innerHTML);
            if (char_min > 0 && char_min > cnt) {
                alert("내용은 "+char_min+"글자 이상 쓰셔야 합니다.");
                return false;
            } 
            else if (char_max > 0 && char_max < cnt) {
                alert("내용은 "+char_max+"글자 이하로 쓰셔야 합니다.");
                return false;
            }
        }
    }

    <?
    if ($is_dhtml_editor) echo cheditor3('wr_content');
    ?>

    if (document.getElementById('tx_wr_content')) {
        if (!ed_wr_content.outputBodyText()) { 
            alert('내용을 입력하십시오.'); 
            ed_wr_content.returnFalse();
            return false;
        }
    }

    var subject = "";
    var content = "";
    $.ajax({
        url: "<?=$board_skin_path?>/ajax.filter.php",
        type: "POST",
        data: {
            "subject": f.wr_subject.value,
            "content": f.wr_content.value
        },
        dataType: "json",
        async: false,
        cache: false,
        success: function(data, textStatus) {
            subject = data.subject;
            content = data.content;
        }
    });

    if (subject) {
        alert("제목에 금지단어('"+subject+"')가 포함되어있습니다");
        f.wr_subject.focus();
        return false;
    }

    if (content) {
        alert("내용에 금지단어('"+content+"')가 포함되어있습니다");
        if (typeof(ed_wr_content) != "undefined") 
            ed_wr_content.returnFalse();
        else 
            f.wr_content.focus();
        return false;
    }

    if (!check_kcaptcha(f.wr_key)) {
        return false;
    }

    document.getElementById('btn_submit').disabled = true;
    //document.getElementById('btn_list').disabled = true;

    <?
    if ($g4[https_url])
        echo "f.action = '$g4[https_url]/$g4[bbs]/write_sellitem_update.php';";
    else
        echo "f.action = './write_sellitem_update.php';";
    ?>
    
    return true;
}

function changeArea(area){
	$("#searchBtn").hide();
	if(area == "1"){
		document.getElementById("wr_area").value = "<?=$member[mb_addr1_1]?>";
	}else if(area == "2"){
		document.getElementById("wr_area").value = "<?=$member[mb_addr2_1]?>";
	}else if(area == "3"){
		document.getElementById("wr_area").value = "<?=$member[mb_addr3_1]?>";
	}else if(area == "4"){
		$("#wr_area").val("");
		$("#searchBtn").show();
	}

}
</script>

<script type="text/javascript" src="<?="$g4[path]/js/board.js"?>"></script>
<script type="text/javascript"> window.onload=function() { drawFont(); } </script>
<script type="text/javascript" src="<?=$g4['path']?>/js/suggest.js"></script>
<script language="JavaScript">
    document.fwrite.itemBrand.obj = 
        sug_set_properties(document.fwrite.itemBrand, '<?=$board_skin_path?>/suggest_search_itemBrand.php', true, true, true);
    document.fwrite.itemName.obj = 
        sug_set_properties(document.fwrite.itemName, '<?=$board_skin_path?>/suggest_search_itemName.php', true, true, true);
</script>
